﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.SessionState;

namespace CH.js.uploadify
{
    /// <summary>
    /// zhoubian_jingqu_uploadifyHandler 的摘要说明
    /// </summary>
    public class zhoubian_jingqu_uploadifyHandler : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            HttpPostedFile file = context.Request.Files["Filedata"];
            string uploadPath = HttpContext.Current.Server.MapPath("\\userimages\\zhoubian_jingqu\\");
            //后台管理员的userid
            int id = 0;
            if (context.Request.QueryString["op"] != null && context.Request.QueryString["op"].Equals("putong"))
            {
                id = Convert.ToInt32(context.Session["userid"]);
            }
            else
            {
                id = Convert.ToInt32(context.Session["useradmin"]);
            }
            if (file != null)
            {
              if (!System.IO.Directory.Exists(uploadPath))
                {
                  System.IO.Directory.CreateDirectory(uploadPath);
                }
                //重命名图片名称
                string filename = id + DateTime.Now.ToString("yyyymmddhhmmss_ffff") + Path.GetExtension(file.FileName);
                file.SaveAs(uploadPath + filename);
                context.Response.Write("1," + filename);
            }
            else
            {
                context.Response.Write("0");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}